package com.example.appsnight;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

//com es un customAdapter, el podriem fer de qualsevol tipus,
//no nomes String, sino de Objectes creats x nosaltres

public class MyCustomAdapterView extends ArrayAdapter<Assistent>{
	private final Context context;
	private final List<Assistent> values;
	
	public MyCustomAdapterView(Context _context, List<Assistent> _values) {
		super(_context,R.layout.item,_values);
		context = _context;
		values = _values;
	}
	
	//tots els components q usen adapters, contenen un getView
	//view grup = pare contenedor
	@Override
	public View getView(int position, View converView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		View rowView = inflater.inflate(R.layout.item, parent, false);
		TextView nomLabel = (TextView)rowView.findViewById(R.id.nomLabel);
		TextView empresaLabel = (TextView)rowView.findViewById(R.id.empresaLabel);
		TextView carrecLabel = (TextView)rowView.findViewById(R.id.carrecLabel);
		
		ImageView fotoView = (ImageView)rowView.findViewById(R.id.fotoView);
		
		nomLabel.setText(values.get(position).getNom()+" "+values.get(position).getCognom());
		empresaLabel.setText(values.get(position).getEmpresa());
		carrecLabel.setText(values.get(position).getCarrec());
		fotoView.setImageBitmap(values.get(position).getFoto());
		
		return rowView;
	}
}
